package moduloIndexacion.frames;


import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JOptionPane;
import javax.swing.JProgressBar;
import javax.swing.JButton;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.SwingConstants;
import java.awt.Component;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.io.File;
import java.util.ArrayList;
import javax.swing.JLabel;
import javax.swing.LayoutStyle.ComponentPlacement;

import moduloIndexacion.gestores.GestorIndexacion;

import java.awt.Toolkit;

public class FrameProcesamiento extends JFrame {

	private JPanel contentPane;
	private GestorIndexacion gestor;

	/**
	 * Create the frame.
	 */
	public FrameProcesamiento( GestorIndexacion gestor ) {
		setResizable(false);
		setIconImage(Toolkit.getDefaultToolkit().getImage(FrameProcesamiento.class.getResource("/resources/ChewieIcon.jpg")));
		this.gestor = gestor;
		initialize();
		
	}

	public void initialize(){
		setTitle("Chewie - Motor de Busqueda de Informaci\u00F3n");
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 580, 340);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		
		JPanel panelInferior = new JPanel();
		contentPane.add(panelInferior, BorderLayout.SOUTH);
		
		final JButton btnCancelar = new JButton("Cancelar");
		btnCancelar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				dispose();
			}
		});
		
		final JButton btnAtras = new JButton("<<");
		btnAtras.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					FrameDocumento frame = new FrameDocumento ( gestor );
					frame.setLocationRelativeTo(null);
					frame.setVisible(true);
					dispose();
				} catch (Exception e1) {
					e1.printStackTrace();
				}
			}
		});
		
		final JButton btnSalir = new JButton("Salir");
		btnSalir.setVisible(false);
		btnSalir.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				dispose();
			}
		});
		
		final JButton btnTerminar = new JButton("Terminar");
		btnTerminar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				gestor.savePosteo();
				JOptionPane.showMessageDialog(contentPane, "Se efectuo la operacion de Grabado", "Grabado", JOptionPane.INFORMATION_MESSAGE);
				btnTerminar.setVisible(false);
				btnCancelar.setEnabled(false);
				btnAtras.setEnabled(false);
				btnSalir.setVisible(true);
			}
		});
		
		
		GroupLayout gl_panelInferior = new GroupLayout(panelInferior);
		gl_panelInferior.setHorizontalGroup(
			gl_panelInferior.createParallelGroup(Alignment.TRAILING)
				.addGroup(gl_panelInferior.createSequentialGroup()
					.addContainerGap(319, Short.MAX_VALUE)
					.addComponent(btnCancelar)
					.addGap(5)
					.addComponent(btnAtras)
					.addGap(5)
					.addComponent(btnTerminar)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(btnSalir)
					.addContainerGap())
		);
		gl_panelInferior.setVerticalGroup(
			gl_panelInferior.createParallelGroup(Alignment.TRAILING)
				.addGroup(gl_panelInferior.createSequentialGroup()
					.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
					.addGroup(gl_panelInferior.createParallelGroup(Alignment.LEADING)
						.addComponent(btnCancelar)
						.addComponent(btnAtras)
						.addGroup(gl_panelInferior.createParallelGroup(Alignment.BASELINE)
							.addComponent(btnTerminar)
							.addComponent(btnSalir)))
					.addContainerGap())
		);
		gl_panelInferior.linkSize(SwingConstants.VERTICAL, new Component[] {btnCancelar, btnAtras, btnTerminar, btnSalir});
		gl_panelInferior.linkSize(SwingConstants.HORIZONTAL, new Component[] {btnCancelar, btnAtras, btnTerminar, btnSalir});
		panelInferior.setLayout(gl_panelInferior);
		
		JPanel panel_1 = new JPanel();
		contentPane.add(panel_1, BorderLayout.CENTER);
		
		JProgressBar progressBar = new JProgressBar();
		
		JLabel lblRutaDeArchivo = new JLabel("Ruta de Archivo que se esta procesando");
		GroupLayout gl_panel_1 = new GroupLayout(panel_1);
		gl_panel_1.setHorizontalGroup(
			gl_panel_1.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel_1.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_panel_1.createParallelGroup(Alignment.LEADING)
						.addComponent(lblRutaDeArchivo)
						.addComponent(progressBar, GroupLayout.DEFAULT_SIZE, 404, Short.MAX_VALUE))
					.addContainerGap())
		);
		gl_panel_1.setVerticalGroup(
			gl_panel_1.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel_1.createSequentialGroup()
					.addGap(65)
					.addComponent(lblRutaDeArchivo)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(progressBar, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
					.addContainerGap(94, Short.MAX_VALUE))
		);
		panel_1.setLayout(gl_panel_1);
		
		JLabel lblCargaDeDocumentos = new JLabel("Carga de Documentos");
		contentPane.add(lblCargaDeDocumentos, BorderLayout.NORTH);
	}
}
